//
//  YYMDreamTravelListCell.m
//  On The Load
//
//  Created by 我爱的妞 on 15/11/11.
//  Copyright © 2015年 @@叶一闽. All rights reserved.
//

#import "YYMDreamTravelListCell.h"
#import "YMDTListCityModel.h"
#import <UIImageView+WebCache.h>

@implementation YYMDreamTravelListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT / 2.3)];
        
        [self.contentView addSubview:_scrollView];
        
        self.mainImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
        _mainImageView.userInteractionEnabled = YES;
        self.mainImageView.backgroundColor = [UIColor blackColor];
        
        [self.scrollView addSubview:self.mainImageView];
        
        self.placeNameCHN = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 2 - 60 * SCALEW, 60 * SCALEH, 120 * SCALEW, 25 * SCALEH)];
        
        self.placeNameCHN.font = [UIFont systemFontOfSize:20];
        self.placeNameCHN.textAlignment = NSTextAlignmentCenter;
        self.placeNameCHN.textColor = [UIColor whiteColor];
        
        [self.contentView addSubview:_placeNameCHN];
        
        self.placeNameENG = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 2 - 60 * SCALEW, 100 * SCALEH, 120 * SCALEW, 25 * SCALEH)];
        
        self.placeNameENG.font = [UIFont systemFontOfSize:13];
        self.placeNameENG.textColor = [UIColor whiteColor];
        self.placeNameENG.textAlignment = NSTextAlignmentCenter;
        
        [self.contentView addSubview:_placeNameENG];
        
        self.contryLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 2 - 40 * SCALEW, 160 * SCALEH, 80 * SCALEW, 25 * SCALEH)];
        
        self.contryLabel.font = [UIFont systemFontOfSize:13];
        self.contryLabel.textColor = [UIColor whiteColor];
        self.contryLabel.textAlignment = NSTextAlignmentCenter;
        self.contryLabel.layer.borderWidth = 1;
        self.contryLabel.layer.borderColor = [UIColor whiteColor].CGColor;
        
        [self.contentView addSubview:_contryLabel];
        
        UIView *view = [[UIView alloc] initWithFrame:CURRENTSCEEN];
        
        view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.35];
        
        [self.mainImageView addSubview:view];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
        [view addGestureRecognizer:tap];
    }
    
    return self;
}

- (void)setModel:(YMDTListCityModel *)model{
    
    _model = model;
    
    self.placeNameCHN.text = model.name;
    self.placeNameENG.text = model.alias;
    self.contryLabel.text = model.country;
    
    [_mainImageView sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:[UIImage imageNamed:@"earth.jpg"]];
}

- (void)setY:(CGFloat)y{
    
    _y = y;
    
    CGRect tempR = _mainImageView.frame;
    tempR.origin.y += y;
    _mainImageView.frame = tempR;
}

- (void)tapAction{
    
    [self.delegate delegateDelegate:self.tag - 1000];
    
}

@end
